package com.app.teaware.bean;

import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.app.teaware.R;
import com.lzy.imagepicker.bean.ImageItem;

import java.io.Serializable;

import my.FileUtils;

public class UploadImgData implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 10000008L;
	private String id;
	private String path;
	private String name;

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	private String url;


	public String getFileName() {

		if(!TextUtils.isEmpty(name))return name;
		if(TextUtils.isEmpty(path))return "";

		return FileUtils.getFileNameFromUrlSimple(path);
	}


    public UploadImgData() {
    }
	public UploadImgData(ImageItem imageItem) {
		this.path = imageItem.path;
	}
    public UploadImgData(String id, String path) {
        this.id = id;
        this.path = path;
    }

    public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public boolean isNeedpost(){
		if(TextUtils.isEmpty(id))return true;
		return false;
//		return !path.startsWith("http");
	}

	@JSONField(serialize =  false)
	public UserUploadFileBean getUploadFileData(){
		UserUploadFileBean fileBean = new UserUploadFileBean();
		fileBean.setId(id);
		fileBean.setUrl(getPath());
		return fileBean;
	}

	public int getImgresByname(){
    	if(TextUtils.isEmpty(path))return  R.drawable.file_icon_other;
		if(path.toLowerCase().endsWith(".pdf")){
			return R.drawable.file_icon_pdf;
		}else if(path.toLowerCase().endsWith(".jpg") || path.toLowerCase().endsWith(".png") || path.toLowerCase().endsWith(".jpeg") ){
			return R.drawable.file_icon_pic;
		}else if(path.toLowerCase().endsWith(".rar") || path.toLowerCase().endsWith(".zip")  ){
			return R.drawable.file_icon_rar;
		}else if(path.toLowerCase().endsWith(".doc") || path.toLowerCase().endsWith(".docx")  ){
			return R.drawable.file_icon_word;
		}else {
			return R.drawable.file_icon_other;
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
